package com.android.RssReader.Provider;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class NewsDatabaseHelper extends SQLiteOpenHelper {

	public static final String NAME = "rss_reader.db";
	private static final int version = 1;
	public static final String TAB_NEWS = "rss_reader_news";
	
	public static final int NEWS_IS_READED = 1;
	public static final int NEWS_IS_UNREAD = 0;
	
	
	public static final String COLUMN_ID = "_id";
	public static final String COLUMN_NEWS_ID = "news_id";
	public static final String COLUMN_NEWS_TITLE = "title";
	public static final String COLUMN_NEWS_DESCRIPTION = "description";
	public static final String COLUMN_NEWS_CONTENT = "content";
	public static final String COLUMN_NEWS_IMAGE = "image";
	public static final String COLUMN_NEWS_LINK = "link";
	public static final String COLUMN_NEWS_SOURCE = "source";
	public static final String COLUMN_NEWS_DATE = "date";
	public static final String COLUMN_NEWS_AUTHOR = "author";
	public static final String COLUMN_NEWS_READED = "readed";
	public static final String COLUMN_NEWS_CATEGORY = "tag";
	private static final String CRETAE_TAB_NEWS = " CREATE TABLE IF NOT EXISTS " + TAB_NEWS + " ( " + COLUMN_ID + " INTEGER PRIMARY KEY , "
	+ COLUMN_NEWS_ID + " TEXT, " + COLUMN_NEWS_TITLE + " TEXT, " + COLUMN_NEWS_DESCRIPTION + " TEXT, " + COLUMN_NEWS_CONTENT + " TEXT, " + COLUMN_NEWS_IMAGE + " TEXT, "+ COLUMN_NEWS_LINK + " TEXT, " + COLUMN_NEWS_SOURCE + " TEXT, "+ COLUMN_NEWS_DATE + " TEXT, " + COLUMN_NEWS_AUTHOR + " TEXT, " + COLUMN_NEWS_READED + " INTEGER," + COLUMN_NEWS_CATEGORY + " INTEGER" + ")";
	
	
	public static final String TAB_FAVORITES_NEWS = "rss_reader_favorites_news";
	
	public static final String COLUMN_FAVORITES_ID = "_id";
	public static final String COLUMN_FAVORITES_NEWS_ID = "news_id";
	public static final String COLUMN_FAVORITES_NEWS_TITLE = "title";
	public static final String COLUMN_FAVORITES_NEWS_DESCRIPTION = "description";
	public static final String COLUMN_FAVORITES_NEWS_CONTENT = "content";
	public static final String COLUMN_FAVORITES_NEWS_IMAGE = "image";
	public static final String COLUMN_FAVORITES_NEWS_LINK = "link";
	public static final String COLUMN_FAVORITES_NEWS_SOURCE = "source";
	public static final String COLUMN_FAVORITES_NEWS_DATE = "date";
	public static final String COLUMN_FAVORITES_NEWS_AUTHOR = "author";
	public static final String COLUMN_FAVORITES_NEWS_READED = "readed";
	public static final String COLUMN_FAVORITES_NEWS_CATEGORY = "tag";
	private static final String CRETAE_FAVORITES_TAB_NEWS = " CREATE TABLE IF NOT EXISTS " + TAB_FAVORITES_NEWS + " ( " + COLUMN_FAVORITES_ID + " INTEGER PRIMARY KEY , "
	+ COLUMN_FAVORITES_NEWS_ID + " TEXT, " + COLUMN_FAVORITES_NEWS_TITLE + " TEXT, " + COLUMN_FAVORITES_NEWS_DESCRIPTION + " TEXT, " + COLUMN_FAVORITES_NEWS_CONTENT + " TEXT, " + COLUMN_FAVORITES_NEWS_IMAGE + " TEXT, "+ COLUMN_FAVORITES_NEWS_LINK + " TEXT, " + COLUMN_FAVORITES_NEWS_SOURCE + " TEXT, "+ COLUMN_FAVORITES_NEWS_DATE + " TEXT, " + COLUMN_FAVORITES_NEWS_AUTHOR + " TEXT, " + COLUMN_FAVORITES_NEWS_READED + " INTEGER," + COLUMN_FAVORITES_NEWS_CATEGORY + " INTEGER" + ")";
	
	
	
	public static final String TAB_CATEGORYS = "rss_reader_categorys";
	
	public static final String COLUMN_NEWS_CAGETORY_ID = "_id";
	public static final String COLUMN_NEWS_CAGETORY_NAME = "name";
	public static final String COLUMN_NEWS_CAGETORY_URL = "url";
	private static final String CRETAE_TAB_CATEGORYS = " CREATE TABLE IF NOT EXISTS " + TAB_CATEGORYS + " ( " + COLUMN_NEWS_CAGETORY_ID + " INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL, "
	+ COLUMN_NEWS_CAGETORY_NAME + " TEXT, " + COLUMN_NEWS_CAGETORY_URL + " TEXT" + ")";
	
	
	public NewsDatabaseHelper(Context context) {
		super(context, NAME, null, version);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		createTabs(db);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
	}
	
	@Override
	public void onOpen(SQLiteDatabase db) {
		super.onOpen(db);
		createTabs(db);
	}
	
	private void createTabs(SQLiteDatabase db) {
		db.execSQL(CRETAE_TAB_NEWS);
		db.execSQL(CRETAE_TAB_CATEGORYS);
		db.execSQL(CRETAE_FAVORITES_TAB_NEWS);
	}

}
